//
//  gongsizhuye.m
//  BAOASystem
//
//  Created by michael on 2018/2/28.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "qiyexqTableViewCell.h"
#import "qiyeproductxqTableViewCell.h"

#import "gongsizhuye.h"

@implementation gongsizhuye
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//    UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
//self.backgroundColor = myColor;
//self.backgroundColor = [UIColor redColor];
          }
    return self;
}
- (void)setDic:(NSDictionary *)dic{



_dic = dic;
[self initview];
}
- (void)initview{

_tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) style:UITableViewStylePlain];
_tableview.backgroundColor = [UIColor whiteColor];
//_tableview.frame = self.frame;
_tableview.dataSource = self;
_tableview.delegate = self;
self.tableview.bounces = NO;
[self addSubview:_tableview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{NSArray *array  =_dic[@"ctglist"];
if (array!= 0) {
return 2;
}else{
    return 1;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *array  =_dic[@"ctglist"];

if (section == 0) {
        return 3;

}else{
    return array.count;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
 if (section==1) {
         UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
         bgView.backgroundColor = [UIColor whiteColor];
           UIView *view = [[UIView alloc]init];
     view.frame = CGRectMake(5, 5, 10, 20);
    view.backgroundColor = [UIColor colorWithHexString:@"0aa0f6"];
[bgView addSubview:view];
     UILabel *label = [[UILabel alloc]init];
 label.frame = CGRectMake(view.right+10,5, 150, 20);
    label.text  = NSLocalizedString(@"产品信息", nil);
    label.textColor = [UIColor colorWithHexString:@"484848"];
   label.font = [UIFont boldSystemFontOfSize:14];
[bgView addSubview:label];
    UIView *view2 = [[UIView alloc]init];
view2.frame = CGRectMake(0, 29, KScreenWidth, 1);
    view2.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    [bgView addSubview:view2];
     
return bgView;
 }else{
 return nil;
 }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==1) {
        return 30;
    }
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section ==0) {
if (indexPath.row ==0) {
    return 100;
}else if (indexPath.row ==1){
    return 30+10+80;

}else{
NSDictionary *dic = _dic[@"company"];
// CGFloat height = [OAToolBox sizebyText:dic[@"businessScope"] font:13 minsWidth:120];
  CGFloat height = [OAToolBox sizebyText:dic[@"address"] font:13 minsWidth:120];
 CGFloat height2 = [OAToolBox sizebyText:dic[@"websites"] font:13 minsWidth:120];
  if ((height>31.5)&&(height2>31.5)) {
 return 30+10+8*32+32+15+15;
}else if(height>31.5){
   return 30+10+8*32+32+15;

}else if(height2>31.5){
   return 30+10+8*32+32+15;

}else{
return 30+10+8*32+32;
}
}
}else{
NSArray *array  =_dic[@"ctglist"];
NSDictionary *dic = array[indexPath.row];
NSArray *list = dic[@"ctgpdlist"];
int num =(int) ceil(list.count/2.0);
return num*150+30;
}
}
//if (indexPath.section == 0)
//{
//    if (indexPath.row ==0)
//{
//    return 100;
//}else if (indexPath.row ==1) {
//    return 30+10+80;
//}else  {
//    return 30+10+9*20;
//}
//}else if (indexPath.section == 1)
//{
//NSArray *array  =_dic[@"ctglist"];
//NSDictionary *dic = array[indexPath.row];
//NSArray *list = dic[@"ctgpdlist"];
//int num =(int) ceil(list.count/2.0);
//return num*100+30;
//
//}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section ==0) {
    

if (indexPath.row ==0){
 static NSString *CellIdentifier0 = @"Cellbendititlepic0";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    NSDictionary *comdic = _dic[@"company"];
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, KScreenWidth-20, 70)];
    [imageview sd_setImageWithURL:[NSURL URLWithString:comdic[@"sceneImage"]] placeholderImage:[UIImage imageNamed:@"加载"]];
    [cell.contentView addSubview:imageview];
    UIView *view  = [[UIView alloc]initWithFrame:CGRectMake(0,imageview.bottom+10 , KScreenWidth, 10)];
    view.backgroundColor  = [UIColor colorWithHexString:@"f0eff5"];
    [cell.contentView addSubview:view];

    return cell;

}else if (indexPath.row ==1){
 static NSString *CellIdentifier1 = @"Cellbendititlepic1";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

//            cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];

    }
        NSDictionary *comdic = _dic[@"company"];
  UIView *view0 = [[UIView alloc]init];
     view0.frame = CGRectMake(0, 0, KScreenWidth, 30);
    view0.backgroundColor = [UIColor whiteColor];
[cell.contentView addSubview:view0];
    UIView *view = [[UIView alloc]init];
     view.frame = CGRectMake(5, 5, 10, 20);
    view.backgroundColor = [UIColor colorWithHexString:@"0aa0f6"];
[cell.contentView addSubview:view];
UILabel *label = [[UILabel alloc]init];
 label.frame = CGRectMake(view.right+10,5, 150, 20);
    label.text  = NSLocalizedString(@"公司简介", nil);
    label.textColor = [UIColor colorWithHexString:@"484848"];
   label.font = [UIFont boldSystemFontOfSize:14];
[cell.contentView addSubview:label];
    UIView *view2 = [[UIView alloc]init];
view2.frame = CGRectMake(0, 29, KScreenWidth, 1);
    view2.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    [cell.contentView addSubview:view2];
    UILabel *label2 = [[UILabel alloc]init];
 label2.frame = CGRectMake(10,view2.bottom, KScreenWidth-20, 80);
 label2.backgroundColor = [UIColor whiteColor];
    label2.text  = comdic[@"newDescription"];
    label2.numberOfLines = 0;
    label2.textColor = [UIColor colorWithHexString:@"484848"];
   label2.font = [UIFont systemFontOfSize:13];
[cell.contentView addSubview:label2];
   UIView *view3 = [[UIView alloc]init];
view3.frame = CGRectMake(0, label2.bottom, KScreenWidth, 10);
    view3.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    [cell.contentView addSubview:view3];
    return cell;
}else {
 static NSString *CellIdentifier2 = @"Cellbendititlepic2";

    qiyexqTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
if (cell==nil) {
        cell=[[qiyexqTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

//            cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];

    }
        NSDictionary *comdic = _dic[@"company"];
cell.dic = comdic;
    return cell;
}
}else{
 static NSString *CellIdentifier20 = @"Cellbendititlepic20";

    qiyeproductxqTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier20];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
if (cell==nil) {
        cell=[[qiyeproductxqTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier20];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }NSArray *array = _dic[@"ctglist"];
        NSDictionary *comdic = array[indexPath.row];
cell.dic = comdic;

    return cell;
}

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
